

// pages/helpinfo/helpinfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    choose:'true',
    helpinfo:[],
    personaltarget:'none',
    // 个人信息
    wxAva:"",
    userName:"",
    academy:"",
    userClass:"",
    contactPhone:"",
  },

  onShow(){
    var that = this;
    wx.request({
      url: 'http://127.0.0.1:8080/helpInfo/helpInfoByHot',
      method:"GET",
      success(res){
        // console.log(res)
        if(res.data != ""){
          for(var i=0;i<res.data.length;i++){
            res.data[i].helpPic=JSON.parse(res.data[i].helpPic)
          }
          that.setData({
            helpinfo:res.data
          })



          // for(var i=0;i<res.data.length;i++){
          //   wx.request({
          //     url: 'http://127.0.0.1:8080/helpInfoJudge/selectJudgeById',
          //     method:"POST",
          //     data:{helpinfoid:res.data[i].helpInfoID},
          //     success(res){
          //       console.log(res)
          //     }
          //   })
          // }

          
        }
      }
    })
  },

  change1(e){
    this.onShow();
    this.setData({
      choose:true
    })
  },
  change2(e){
    var that = this;
    wx.request({
      url: 'http://127.0.0.1:8080/helpInfo/helpInfoByTime',
      method:"GET",
      success(res){
        // console.log(res)
        if(res.data != ""){
          for(var i=0;i<res.data.length;i++){
            res.data[i].helpPic=JSON.parse(res.data[i].helpPic)
          }
          that.setData({
            helpinfo:res.data
          })


          
        }
      }
    })
    this.setData({
      choose:false
    })
  },
  showperson(e){
    if(wx.getStorageSync('isuser') == "yes"){
       // console.log(e)
    var index = e.currentTarget.dataset.index;
    var user = this.data.helpinfo[index]
    // console.log(user)
    this.setData({
      wxAva:user.wxAva,
      userName:user.userName,
      academy:user.academy,
      userClass:user.userClass,
      contactPhone:user.phone,
      personaltarget:false
    })
    }else{
       wx.showToast({
      title: '身份未通过审核',
      duration: 1000,
      icon: "error",
      success: (res) => {},
    })
    }

  },
  cancelperson(e){
    this.setData({
      personaltarget:'none'
    })
  },
  choosehelp(e){
    // console.log(e)
    var index = e.currentTarget.dataset.index;
    var helpinfoid = this.data.helpinfo[index].helpInfoID;
    wx.navigateTo({
      url: '/pages/helpdetail/helpdetail?helpinfoid='+helpinfoid,
    })
  },
  collect(e){
    var index = e.currentTarget.dataset.index;
    var value = 'helpinfo['+index+'].collect';
    var text = this.data.helpinfo[index].collect;
    this.setData({
      [value]:!text
    })
  }


})